<?php
/**
 *  后台操作日志记录控制器
 *
 * @author liang<lang@vip.deyi.com>
 * @since   2016/11/30 15:10
 * @copyright  deyi.com
 */

namespace Apps\Acp\Controllers;

use Apps\Acp\Models\ManagerLog;
use Apps\Common\Constant\BusinessConstant;
use Apps\Common\Controller\AcpBaseController;
use Deyi\Functions\PageFunction;

/**
 * Class LogController
 * @package Apps\Ad\Controllers
 */
class LogController extends AcpBaseController
{
    public function indexAction()
    {
        $page = PageFunction::getPageAndOffset($this->getParamValue('page', 1, 'int'), BusinessConstant::PAGE_SIZE);
        $name = $this->getParamValue('name', '');

        $conditions = [];

        if ($name) {
            $conditions['uid'] = intval($name);
        }

        $total = ManagerLog::getInstance()->countListByConds($conditions);
        $list = [];
        if ($total > 0) {
            $list = ManagerLog::getInstance()->getListByConds($conditions, $page['offset'], $page['size']);
        }

        $this->view->setVars(
            [
                'list' => $list,
                'pageHtml' => PageFunction::getPageHtml(
                    $page['page'],
                    $total,
                    $page['size'],
                    parse_url($this->request->getURI())['path'],
                    $conditions,
                    4
                )
            ]
        );
    }

    public function cleanLogAction()
    {
        $time = time() - 365 * 24 * 3600;

        ManagerLog::getInstance()->deleteByDateline($time);

        parent::renderSuccessJson();
    }
}